/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package hibernate;

import com.partaljevic.gambling.beans.Ticket;
import com.partaljevic.tapestry.gambling.service.TicketService;
import java.io.Serializable;
import java.util.List;
import org.hibernate.Criteria;
import org.hibernate.Session;

/**
 *
 * @author Nemanja
 */
public class TicketServiceHibernate implements TicketService{

    private final Session session;

    public TicketServiceHibernate(Session session) {
        this.session = session;
    }

    @Override
    public Ticket save(Ticket ticket) {
        return (Ticket) session.get(Ticket.class, session.save(ticket));
    }

    @Override
    public List<Ticket> retrieve() {
        Criteria criteria = session.createCriteria(Ticket.class);
        return criteria.list();
    }

    @Override
    public Ticket retrieve(Serializable id) {
        return (Ticket)session.get(Ticket.class, id);
    }

    @Override
    public void update(Ticket ticket) {
        session.saveOrUpdate(ticket);
    }

}
